<script type="text/javascript" src="<?php echo base_url(); ?>content/js/jquery.form.min.js"></script>
<script type="text/javascript"><!--//--><![CDATA[//><!--

	/*function afterSuccess()
	{
		$('#submit-btn2').show(); //hide submit button
		$('#loading-img').hide(); //hide submit button

	}

	//function to check file size before uploading.
	function beforeSubmit2(){
	    //check whether browser fully supports all File API
	   if (window.File && window.FileReader && window.FileList && window.Blob)
		{
			
			if( !$('#imageInput').val()) //check empty input filed
			{
				$("#output").html("Are you kidding me?");
				return false
			}
			
			var fsize = $('#imageInput')[0].files[0].size; //get file size
			var ftype = $('#imageInput')[0].files[0].type; // get file type
			

			//allow only valid image file types 
			switch(ftype)
	        {
	            case 'image/png': case 'image/gif': case 'image/jpeg': case 'image/pjpeg':
	                break;
	            default:
	                $("#output").html("<b>"+ftype+"</b> Unsupported file type!");
					return false
	        }
			
			//Allowed file size is less than 1 MB (1048576)
			if(fsize>1048576) 
			{
				$("#output").html("<b>"+bytesToSize(fsize) +"</b> Too big Image file! <br />Please reduce the size of your photo using an image editor.");
				return false
			}
					
			$('#submit-btn2').hide(); //hide submit button
			$('#loading-img').show(); //hide submit button
			$("#output").html("");  
		}
		else
		{
			//Output error to older unsupported browsers that doesn't support HTML5 File API
			$("#output").html("Please upgrade your browser, because your current browser lacks some new features we need!");
			return false;
		}
	}

	//function to format bites bit.ly/19yoIPO
	function bytesToSize(bytes) {
	   var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
	   if (bytes == 0) return '0 Bytes';
	   var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
	   return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
	}*/


	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};


	$(document).ready(function() {
/*
		var kode_desain_auto = "<?php echo $kode_desain_auto; ?>";

		var options = { 
			target:   '#output',   // target element(s) to be updated with server response 
			beforeSubmit:  beforeSubmit2,  // pre-submit callback 
			success:       afterSuccess,  // post-submit callback 
			resetForm: true        // reset the form after successful submit 
		}; 
		
	 	$('#form_master3').submit(function() { 
			$(this).ajaxSubmit(options); 
			//$('#form_master3').remove();
			// always return false to prevent standard browser submit and page navigation 
			return false; 
		}); */
		

		// Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center', rowspan:2},				
				{ field : 'kode_promosi', title : 'Kode Promosi', width:100, sortable:true, rowspan:2},
				{ field : 'tgl_perm', title : 'Tanggal Permintaan', width:130, sortable:true, rowspan:2},
				{ field : 'id_departemen_pk', title : 'ID Departemen', width:150, sortable:true, rowspan:2},
				{ field : 'nama_departemen', title : 'Nama Departemen', width:200, sortable:true, rowspan:2},
				{ field : 'status_permintaan', title : 'Status Permintaan', width:100, sortable:true, rowspan:2},
				{ field : 'nama_desain', title : 'Nama Desain', width:100, sortable:true, rowspan:2},
				{ field : 'jenis_design_val', title : 'Jenis Desain', width:100, sortable:true, rowspan:2},
				{ field : 'keterangan', title : 'Keterangan', width:150, sortable:true, rowspan:2},
				]]
		});
	
		
	// Set Action Button
        var buttons = [
                        // ----- >> Add Button
                        /*{ label: 'Add', icon: 'add', onclick: function() {
							loadPage(gs_path + '/' + controller + '/create/');
                        }},*/
                        
                        // ----- >> Edit Button
					    { label: 'Edit', icon: 'edit', onclick: function() {
					        var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            $.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
					        } else {
								loadPage(gs_path + '/' + controller + '/edit/?kode_promosi='+urlencode(oSel.kode_promosi));
					        } 
					    }},
					    // ----- >> Delete Button
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['kode_promosi']);
							} 
					    }} ];
        setAction(buttons);
		
		
		$('#fm_search').focusFirst();
	});
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>

<!-- 
<div id="dialog_container" style="padding:5px;width:600px;height:250px;">
	<form action="<?php echo base_url(); ?>pro_desain_promo/processupload" id="form_master3" method="post" enctype="multipart/form-data">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
        <td class="label" style="width:150px">Kode Desain</td>
        <td><input id="kode_desain" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama Desain</td>
        <td><input id="nama_desain" /></td>
    </tr>    
    <tr>
        <td class="label" style="width:150px">Jenis Desain</td>
        <td><input id="jenis_desain" /></td>
    </tr>
	<tr>
		<td class="label" style="width:150px">Keterangan</td>
        <td><textarea id="keterangan" rows="5" name="keterangan"  />
        	<input type="file" name="ImageFile" id="imageInput">
        	<input type="submit">
        </td>
	</tr>
    <input type="hidden" name="foto_name2" id="foto_name2">
    
    </form>    
	<tr>
        <td class="label" style="width:150px">Upload Desain</td>
        <td><form action="<?php echo base_url(); ?>pro_desain_promo/processupload" method="post" enctype="multipart/form-data" id="MyUploadForm">
			<input name="ImageFile" id="imageInput" type="file" />
			<input type="submit"  id="submit-btn2" value="Upload" />
			<img src="<?php echo base_url(); ?>content/images/ajax-loader.gif" id="loading-img" style="display:none;" alt="Please Wait"/>
			</form>
			<div id="output"></div>
		</td>
    </tr> 
    </table>
	</form> 
</div> -->